﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Configuration;

namespace RedisSessionStore.Configuration
{
	public class RedisSessionConfig
	{
		#region Configuration
		private static string DefaultCookieName = "redis_session";
		private static volatile SessionStateSection _ConfigSection;
		private static Object _ConfigSectionLocker = new Object();

		protected static SessionStateSection Configuration
		{
			get
			{
				if (_ConfigSection == null)
				{
					lock (_ConfigSectionLocker)
					{
						if (_ConfigSection == null)
						{
							var cfg = WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
							_ConfigSection = (SessionStateSection)cfg.GetSection("system.web/sessionState");
						}
					}
				}

				return _ConfigSection;
			}
		}

		public static String CookieName
		{
			get
			{
				return String.IsNullOrWhiteSpace(Configuration.CookieName) ? DefaultCookieName : Configuration.CookieName;
			}
		}

		#endregion
	}
}
